import _slicedToArray from '@babel/runtime/helpers/esm/slicedToArray';
import { Form } from 'antd';
import sortedUniq from 'lodash/sortedUniq';
import React from 'react';
import { useFormContext } from '../contexts/FormContext';
/**
 * WhenWrap 逻辑隐藏容器
 * @param props
 * @returns
 */
var WhenWrap = function WhenWrap(_ref) {
  var when = _ref.when,
    children = _ref.children;
  var form = useFormContext();
  if (when) {
    var _ref2 = when !== null && when !== void 0 ? when : [],
      _ref3 = _slicedToArray(_ref2, 2),
      _ref3$ = _ref3[0],
      predicate =
        _ref3$ === void 0
          ? function () {
              return true;
            }
          : _ref3$,
      _ref3$2 = _ref3[1],
      dependencies = _ref3$2 === void 0 ? [] : _ref3$2;
    return /*#__PURE__*/ React.createElement(
      Form.Item,
      {
        noStyle: true,
        dependencies: sortedUniq(dependencies),
      },
      function (_ref4) {
        var getFieldsValue = _ref4.getFieldsValue;
        var vals = getFieldsValue();
        var predicated = predicate(vals, form);
        return predicated ? children : null;
      },
    );
  }
  return /*#__PURE__*/ React.createElement(React.Fragment, null, children);
};
export default WhenWrap;
